# coding : UTF-8
import re
import time
import urllib
import urllib.request


def get_html_text(url):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    request = urllib.request.Request(url=url, headers=headers)
    html = urllib.request.urlopen(request).read()

    html = html.decode('utf-8')

    reg = r'href="(.+?\.jpg)" rel=nofollow'
    imgre = re.compile(reg)
    imglist = re.findall(imgre, html)
    x = 0
    for imgurl in imglist:
        try :
            urllib.request.urlretrieve(imgurl, './download/%s.jpg' % x)
        except Exception as e:
            print(e)
        else:
            print("download image%d over!" %x)
        x += 1

if __name__ == '__main__':
    get_html_text("http://www.360doc.com/content/11/0916/09/535749_148649134.shtml")
    while True:
        time.sleep(1)
        print("over!")

			

